# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'Desktop/test.ui'
#
# Created: Sun Mar 14 13:23:47 2010
#      by: PyQt4 UI code generator 4.7
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from sys import *
import anydbm

class Ui_Form(QtGui.QDialog):
    def __init__(self, parent = None):
        super(Ui_Form, self).__init__(parent)
        self.setupUi(self)
        
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(597, 444)
        self.plainTextEdit = QtGui.QTextEdit(Form)
        self.plainTextEdit.setGeometry(QtCore.QRect(10, 30, 301, 401))
        self.plainTextEdit.setObjectName("plainTextEdit")
        self.plainTextEdit_2 = QtGui.QTextEdit(Form)
        self.plainTextEdit_2.setGeometry(QtCore.QRect(320, 30, 261, 391))
        self.plainTextEdit_2.setObjectName("plainTextEdit_2")

        self.retranslateUi(Form)
        QtCore.QObject.connect(self.plainTextEdit, QtCore.SIGNAL("textChanged()"), self.changePlainText2)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
    
    #################################################################
    def scanWhiteSpace(self,scannedText):
        if scannedText == "":
            return True
        else:
            return False
    
    def scanLetter(self, scannedText):
        if (scannedText >= 'A' and scannedText <= 'Z') or (scannedText >= 'a' and scannedText <= 'z'):
            return True
        else:
            return False 
        
    def scanDigits(self, scannedText):
        if scannedText >= 0 and scannedText <= 9:
            return True
        else:
            return False
        
    def scanOperators(self, scannedText):
        if scannedText == '+' or scannedText == '_' or scannedText =='*':
            return True
        else:
            return False
    
    def addToken(self,LEXIM,TYPE):
        TOKENS_DB = anydbm.open('TOKENS','c')
        TOKENS_DB[LEXIM] = TYPE
    
    
    def filterTokens(self,currentCharacter):
        '''
        this functions accept the scanned text and flter tokents and add it to the virtual DB
        '''
        stringBuffer=""
        while 1:
            if self.scanOperators(currentCharacter):
                stringBuffer+=currentCharacter
                return stringBuffer
            
            elif self.scanDigits(currentCharacter):
                stringBuffer=""
                stringBuffer+=currentCharacter
                return stringBuffer
                
            
            
    
    def changePlainText2(self):
            self.plainTextEdit_2.append("Lexim"+"\t\t"+"Type")
            TOKENS_DB = anydbm.open('TOKENS','c')
            PlainTxt=self.plainTextEdit.toPlainText()
            for i in ['a','b','d','e','l','h','a','m','i','d']:
                TOKENS_DB[i]= 'letter'
            for key,value in TOKENS_DB.iteritems():
                self.plainTextEdit_2.append(key+"\t\t"+value)
                
if __name__ == '__main__':
    app = QtGui.QApplication(argv)
    abstract_window = Ui_Form()
    abstract_window.show()
    app.exec_()